package nextoffer;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * @author ：szq
 * @date ：Created in 2022/3/19 10:02
 * @description：剑指 Offer 32 - II. 从上到下打印二叉树 II
 * @modified By：
 * @version: $
 */
public class printBinaryTreesFromTopToBottom {
    class Solution {
        public List<List<Integer>> levelOrder(TreeNode root) {
            if(root==null) return new  LinkedList<List<Integer>>();
            Queue<TreeNode> que = new LinkedList<>();
            List<List<Integer>> res = new ArrayList<>();
            que.add(root);
            while(!que.isEmpty())
            {
                int num =  que.size();
                List<Integer>  re = new ArrayList<>();
                while(num-->0)
                {
                    TreeNode node = que.poll();
                    System.out.println(node);
                    que.add(node.left);
                    que.add(node.right);
                    re.add(node.val);
                }
                res.add(re);
            }
            return  res;




        }
    }
}
